package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.ZhhqCanteenorder;
import com.ruoyi.zhhq.service.IZhhqCanteenorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐厅订单Controller
 * 
 * @author ZLC
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/zhhq/canteenorder")
public class ZhhqCanteenorderController extends BaseController
{
    @Autowired
    private IZhhqCanteenorderService zhhqCanteenorderService;

    /**
     * 查询餐厅订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhhqCanteenorder zhhqCanteenorder)
    {
        startPage();
        List<ZhhqCanteenorder> list = zhhqCanteenorderService.selectZhhqCanteenorderList(zhhqCanteenorder);
        return getDataTable(list);
    }

    /**
     * 导出餐厅订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:export')")
    @Log(title = "餐厅订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhhqCanteenorder zhhqCanteenorder)
    {
        List<ZhhqCanteenorder> list = zhhqCanteenorderService.selectZhhqCanteenorderList(zhhqCanteenorder);
        ExcelUtil<ZhhqCanteenorder> util = new ExcelUtil<ZhhqCanteenorder>(ZhhqCanteenorder.class);
        util.exportExcel(response, list, "餐厅订单数据");
    }

    /**
     * 获取餐厅订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(zhhqCanteenorderService.selectZhhqCanteenorderByOrderId(orderId));
    }

    /**
     * 新增餐厅订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:add')")
    @Log(title = "餐厅订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhhqCanteenorder zhhqCanteenorder)
    {	
    	try {
    		zhhqCanteenorderService.insertZhhqCanteenorder(zhhqCanteenorder);
    		return AjaxResult.success("添加成功！");
		} catch (Exception e) {
			return AjaxResult.error("添加失败！");
		}   
    }

    /**
     * 修改餐厅订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:edit')")
    @Log(title = "餐厅订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhhqCanteenorder zhhqCanteenorder)
    {
        return toAjax(zhhqCanteenorderService.updateZhhqCanteenorder(zhhqCanteenorder));
    }

    /**
     * 删除餐厅订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:canteenorder:remove')")
    @Log(title = "餐厅订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(zhhqCanteenorderService.deleteZhhqCanteenorderByOrderIds(orderIds));
    }
}
